<?php
class model_user extends CI_Model
{
	protected $_table = "tbl_users";
	public function __construct(){
		parent::__construct();
	}
	public function checkLog($user,$pass){
		$this->db->where("user_name",$user); //where user_name = '$name'
		$this->db->where("user_pass",$pass); //where user_pass = '$pass'
		$query = $this->db->get($this->_table);
		$numrows = $query->num_rows(); 
		if($numrows > 0){ // Login true
			return $query->row_array(); // ~~ fetch()
						   // result_array() ~~ fetchAll()
		}else{
			return FALSE;
		}
	}
	public function checkuser($field,$val,$id=""){
		if($id != ""){
			$this->db->where("user_id !=",$id);
		}
		$this->db->where($field,$val);
		$numrows = $this->db->count_all_results($this->_table);
		if($numrows > 0){
			return FALSE;
		}else{
			return TRUE;
		}
	}
	public function totalUsers(){
		return $this->db->count_all($this->_table);
	}
	public function listUsers($off,$start){
		$this->db->limit($off,$start);
		return $this->db->get($this->_table)->result_array();
	}
	public function getdata($id){
		$this->db->where("user_id",$id);
		return $this->db->get($this->_table)->row_array();
	}
	public function addNew($data){
		$this->db->insert($this->_table,$data);
	}
	public function update($id,$data){
		$this->db->where("user_id",$id);
		$this->db->update($this->_table,$data);
	}
	public function delUser($id){
		$this->db->where("user_id",$id);
		$this->db->delete($this->_table);
	}
}